package net.maku.project.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.project.convert.ProcessStepsConvert;
import net.maku.project.entity.ProcessStepsEntity;
import net.maku.project.service.ProcessStepsService;
import net.maku.project.query.ProcessStepsQuery;
import net.maku.project.vo.ProcessStepsVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 流程环节表
*
* @author aili 1106997025@qq.com
* @since 1.0.0 2024-07-09
*/
@RestController
@RequestMapping("project/process-steps")
@Tag(name="流程环节表")
@AllArgsConstructor
public class ProcessStepsController {
    private final ProcessStepsService processStepsService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('project:process-steps:page')")
    public Result<PageResult<ProcessStepsVO>> page(@ParameterObject @Valid ProcessStepsQuery query){
        PageResult<ProcessStepsVO> page = processStepsService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('project:process-steps:info')")
    public Result<ProcessStepsVO> get(@PathVariable("id") Long id){
        ProcessStepsEntity entity = processStepsService.getById(id);

        return Result.ok(ProcessStepsConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('project:process-steps:save')")
    public Result<String> save(@RequestBody ProcessStepsVO vo){
        processStepsService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('project:process-steps:update')")
    public Result<String> update(@RequestBody @Valid ProcessStepsVO vo){
        processStepsService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('project:process-steps:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        processStepsService.delete(idList);

        return Result.ok();
    }
}